package com.chenwut.threadDemo.exercise_1;

public class MyThread01 extends Thread {
    static int ticket = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread01.class) {
                if (ticket == 100) {
                    break;
                }
                try {
                    Thread.sleep(10);
                    ticket++;
                    System.out.println(getName() + " 发放了 票：" + ticket + " 剩余票数为： " + (100 - ticket));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
